class Solution(object):
    def threeSum(self, nums):
        """
        :type nums: List[int]
        :rtype: List[List[int]]
        """
        nums.sort()
        res = []
        for i in range(0, len(nums)):
            if i != 0 and (nums[i - 1] == nums[i]):
                continue
            target = -nums[i]
            left = i+1
            right = len(nums)-1
            while left < right:
                sum = nums[left]+nums[right]
                if sum == target:
                    temp=[nums[i], nums[left], nums[right]]
                    res.append(temp)
                    left += 1
                    right -= 1
                    while left < right and nums[left] == nums[left-1]:
                        left += 1
                    while left < right and nums[right] == nums[right+1]:
                        right -= 1
                elif sum > target:
                    right -= 1
                else:
                    left += 1

        return res


t = Solution()
print(t.threeSum([-1, 0, 1, 2, -1, -4]))

